<?php

	/**
	 * Elgg tags
	 * Displays a list of tags, separated by commas
	 * 
	 * Tags can be a single string (for one tag) or an array of strings
	 * 
	 * @package Elgg
	 * @subpackage Core
	 * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU Public License version 2
	 * @author Curverider Ltd
	 * @copyright Curverider Ltd 2008
	 * @link http://elgg.org/
	 * 
	 * @uses $vars['tags'] The tags to display
	 * @uses $vars['tagtype'] The tagtype, optionally
	 */

	if (!empty($vars['subtype'])) {
		$subtype = "&subtype=" . urlencode($vars['subtype']);
	} else {
		$subtype = "";
	}
	if (!empty($vars['object'])) {
		$object = "&object=" . urlencode($vars['object']);
	} else {
		$object = "";
	}

	if (empty($vars['tags']) && !empty($vars['value']))
		$vars['tags'] = $vars['value'];

  if (!empty($vars['tags'])) {
    $tagInput = "";
    $tagstr = "";
    
    if (!is_array($vars['tags']))
      $vars['tags'] = array($vars['tags']);

    foreach($vars['tags'] as $tag) {
      if (!empty($tagstr)) {
        $tagstr .= ", ";
        $tagInput .= ", ";
      }
      if (!empty($vars['type'])) {
        $type = "&type={$vars['type']}";
      } else {
        $type = "";
      }
      if (is_string($tag)) {
        $tagstr .= "<a href=\"{$vars['url']}search/?tag=".urlencode($tag) . "{$type}{$subtype}{$object}\">{$tag}</a>";
        $tagInput .= $tag;
      }
    }
    echo $tagstr;
  }
  $access_id = isset($vars['entity']->access_id) ? $vars['entity']->access_id : 0;
  $access_label = elgg_echo('access');
  $access_input = elgg_view('input/access', array('internalname' => 'access_id', 'value' => $access_id));
?>

<div id="prefBox" style="display:none;">
  <p><?php echo elgg_echo('europass:explanation')?></p>
  <form action="<?php echo $vars['url'] ?>action/europass/edit" method="post" id="euroPrefForm">
    <p>
      <label><?php echo elgg_echo('tags') ?></label><br />
      <input type="hidden" name="guid" value="<?php echo $vars['euroGuid'] ?>" />
      <input name="tags" type="text" value="<?php echo $tagInput ?>" />
    </p>
    <p>
      <label><?php echo elgg_echo('europass:exporttext') ?></label><br />
      <?php 
        $on = ($vars['entity']->export == true) ? elgg_echo('europass:export') : '';
      ?>
      <?php echo elgg_view("input/checkboxes", array('options' => array(elgg_echo('europass:export')), 'internalname' => 'export', 'value' => $on ));?>
    </p>
    <p>
      <label><?php echo $access_label ?></label><br />
      <?php echo $access_input ?>
  	</p>
    <input type="submit" value="OK" />
  </form>
</div>
<script type="text/javascript">
  $(document).ready(function() {
    $('a#euroEditPref').fancybox({'overlayShow' :true, 'overlayOpacity': .5});
    <?php if (strpos($_SERVER['HTTP_REFERER'], 'europass/edit')) : ?>
    $('a#euroEditPref').click();
    <?php endif; ?>
  });
</script>